package com.liu.jdbc.myjdbc;
import org.junit.Test;
import utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UtilExercise {
    @Test
    public void testDML(){
        //创建连接
        Connection conn = null;
        PreparedStatement ps = null;


        try {
            conn = JDBCUtil.getConnection();
            //需要做的操作
            String sql = "insert into admin values (?,?)";
            ps = conn.prepareStatement(sql);
            //给占位符赋值
            ps.setInt(1, 5);
            ps.setString(2, "admin");
            //执行
            ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            //关闭资源
            JDBCUtil.close(null,ps,conn);
        }

    }
}
